package mahmoud.sigir.search;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Random;
import java.util.Scanner;

import mahmoud.utils.MinHeap;

//import org.apache.commons.collections.buffer.PriorityBuffer;

public class VPTest {

	/**
	 * @param args
	 */
	DistanceResult[] data;
	String filename = "1distance.dat";
	
	public VPTest()
	{
		loadData();
	}
	public void loadData()
	{
		try 
		{
			BufferedReader fr = new BufferedReader(	new FileReader(filename));
			int count=0;
			while(fr.readLine()!=null)
			{
				count++;
			}
			data = new DistanceResult[count];
			fr.close();
			fr = new BufferedReader(new FileReader(filename));
			String text;
			count =0;
			while((text=fr.readLine())!=null)
			{
				String[] tokens = text.split("\t");
				data[count]= new DistanceResult(Integer.parseInt(tokens[0]), Double.parseDouble(tokens[1]), Double.parseDouble(tokens[2]));
				count++;
			}
			Arrays.sort(data);
			System.out.println(data[0]);
//			System.out.println(data[]);
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
		}
		
	}
//	public static void main(String[] args)
//	{
//		
////		VPTest vpt = new VPTest();
//		PriorityBuffer BF = new PriorityBuffer(20);
//		int top =1000;
//		int total = 10000;
//		int maxRand = 200000;
//		boolean testFailed = false;
//		ArrayList<Integer> fromArrayList = new ArrayList<Integer>();
//		ArrayList<Integer> fromHeap = new ArrayList<Integer>();
//		Random gen = new Random();
//		
//		for(int i = 0 ; i<total ; i++)
//		{
//			fromArrayList.add(gen.nextInt(maxRand));
//		}
//		
//		
//		for (Integer x : fromArrayList)
//		{
//				BF.add(x);
//				System.out.println("Heap size: "+ BF.size());
//		}
////		System.exit(0);
//		//save the heap-selected top results to an arraylist 
//		while (!BF.isEmpty())
//		{
//			 fromHeap.add((Integer) BF.remove());
//		}
//		
////		Collections.sort(fromArrayList,Collections.reverseOrder());
//		Collections.sort(fromArrayList);
//		ArrayList<Integer>  al = new ArrayList<Integer>( fromArrayList.subList(0, top));
//		Collections.sort(al);
//		for (int j = 0; j< top ; j++)
//		{
////			System.out.println("AL : "+al.get(j)+ "\t From Heap: "+fromHeap.get(j));
//			if(!fromHeap.get(j).equals(al.get(j))  )
//			{
//				System.out.println("AT Index : "+j+" AL : "+al.get(j)+ "\t From Heap: "+fromHeap.get(j));
//				testFailed= true;
//			}
//		}
//		if(testFailed)
//			System.out.println("The HEap didnt work as expected");
//		else
//			System.out.println("Test Successfull..!");
//
//	}

}
